#include <stdio.h>

#define LOWER 0
#define UPPER 300
#define STEP 20

#define WORD_IN 1
#define WORD_OUT 0

#define MAX_LINE 1000

char line[MAX_LINE];
char longest[MAX_LINE];
int max;

int power(int base, int n);
int getline(char line[], int limit);
void copy(char to[], char from[]);
int getline_2(void);
void copy_2(void);

void program_1_1_1();
void program_1_1_2();
void program_1_2_1();
void program_1_3_1();
void program_1_4_1();
void program_1_5_1();
void program_1_5_2();
void program_1_5_3();
void program_1_5_4();
void program_1_5_5();
void program_1_5_6();
void program_1_5_7();
void program_1_5_8();
void program_1_5_9();

main()
{
	//program_1_1_1();
	//program_1_1_2();
	//program_1_2_1();
	//program_1_3_1();
	//program_1_4_1();
	//program_1_5_1();
	//program_1_5_2();
	//program_1_5_3();
	//program_1_5_4();
	//program_1_5_5();
	//program_1_5_6();
	//program_1_5_7();
	//program_1_5_8();
	program_1_5_9();

	return 0;
}

int power(int base, int n)
{
	int i, p = 1;
	for ( i = 0; i < n; ++i )
		p *= base;
	return p;
}

int getline(char line[], int limit)
{
	int c, i;
	for ( i = 0; i < limit-1 && (c=getchar())!=EOF && c!='\n'; ++i )
		line[i] = c;
	if ( c == '\n' ) {
		line[i] = c;
		++i;
	}
	line[i] = '\0';
	return i;
}

void copy(char to[], char from[])
{
	int i = 0;
	while ( (to[i] = from[i]) != '\0' )
		++i;
}

int getline_2(void)
{
	int c, i;
	extern char line[];
	for ( i = 0; i < MAX_LINE-1 && (c=getchar())!=EOF && c!='\n'; ++i )
		line[i] = c;
	if ( c == '\n' ) {
		line[i] = c;
		++i;
	}
	line[i] = '\0';
	return i;
}

void copy_2(void)
{
	int i;
	extern char line[], longest[];
	i = 0;
	while ( (longest[i] = line[i]) != '\0' )
		++i;
}

void program_1_1_1()
{
	printf("hello, world\n");
}

void program_1_1_2()
{
	printf("hello, ");
	printf("world");
	printf("\n");
}

void program_1_2_1()
{
	float fahr, celsius;
	float lower, upper, step;

	lower = 0.0f;
	upper = 300.0f;
	step = 20.0f;

	fahr = lower;
	while ( fahr <= upper ) {
		celsius = (5.0f/9.0f) * (fahr-32.0f);
		printf("%3.0f %6.1f\n", fahr, celsius);
		fahr += step;
	}
}

void program_1_3_1()
{
	int fahr;
	for ( fahr = 0; fahr <= 300; fahr += 20 )
		printf("%3d %6.1f\n", fahr, (5.0f/9.0f) * (fahr-32));
}

void program_1_4_1()
{
	int fahr;
	for ( fahr = LOWER; fahr <= UPPER; fahr += STEP )
		printf("%3d %6.1f\n", fahr, (5.0f/9.0f) * (fahr-32));
}

void program_1_5_1()
{
	int c;
	while ( (c = getchar()) != EOF )
		putchar(c);
}

void program_1_5_2()
{
	long nc = 0;
	while ( getchar() != EOF )
		++nc;
	printf("%ld\n", nc);
}

void program_1_5_3()
{
	double nc;
	for ( nc = 0; getchar() != EOF; ++nc )
		;
	printf("%.0f\n", nc);
}

void program_1_5_4()
{
	int c, nl = 0;
	while ( (c = getchar()) != EOF )
		if ( c == '\n' )
			++nl;
	printf("%d\n", nl);
}

void program_1_5_5()
{
	int c, nl = 0, nw = 0, nc = 0, state = WORD_OUT;
	while ( (c = getchar()) != EOF ) {
		++nc;
		if ( c == '\n' )
			++nl;
		if ( c == ' ' || c == '\n' || c == '\t' )
			state = WORD_OUT;
		else if ( state == WORD_OUT ) {
			state =
				WORD_IN;
			++nw;
		}
	}
	printf("%d %d %d\n", nl, nw, nc);
}

void program_1_5_6()
{
	int c, i, nwhite = 0, nother = 0;
	int ndigit[10];

	for ( i = 0; i < 10; ++i )
		ndigit[i] = 0;

	while ( (c = getchar()) != EOF )
		if ( c >= '0' && c <= '9' )
			++ndigit[c-'0'];
		else if ( c == ' ' || c == '\n' || c == 't' )
			++nwhite;
		else
			++nother;

	for ( i = 0; i < 10; ++i )
		printf("digit(%d): %d\n", i, ndigit[i]);
	printf("white space: %d\n", nwhite);
	printf("other: %d\n", nother);
}

void program_1_5_7()
{
	int i;
	for ( i = 0; i < 10; ++i )
		printf("%-2d %-3d %-6d\n", i, power(2, i), power(-3, i));
}
void program_1_5_8()
{
	int len;
	int max;
	char line[MAX_LINE];
	char longest[MAX_LINE];

	max = 0;
	while ( (len = getline(line, MAX_LINE)) > 0 )
		if ( len > max ) {
			max = len;
			copy(longest, line);
		}
	if ( max > 0 )
		printf("%s", longest);
}

void program_1_5_9()
{
	int len;
	extern int max;
	extern char longest[];

	while ( (len = getline_2()) > 0 )
		if ( len > max ) {
			max = len;
			copy_2();
		}
	if ( max > 0 )
		printf("%s", longest);
}
